package Diffenent;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class Get2 {
	static Map<String, String> nameInfos = new LinkedHashMap<String, String>();

	public static void main(String[] args) {
        List<String> fileTheroy = readFileAll_Info("c:\\x\\theroyVersion.txt");
 		List<String> fileActual = readFileAll_Info("c:\\x\\actualVersion.txt");
		List diffList = diff(fileActual, fileTheroy);
		System.out.println("实际有，理论没有：");
		for (int i = 0; i < diffList.size(); i++) {
			System.out.println(diffList.get(i));
		}
		List diffList2 = diff(fileTheroy, fileActual);
		System.out.println("理论有，实际没有：：");
		for (int i = 0; i < diffList2.size(); i++) {
			System.out.println(diffList2.get(i));
		}
	}

	public static List diff(List ls, List ls2) {
		List list = new ArrayList(Arrays.asList(new Object[ls.size()]));
		Collections.copy(list, ls);
		list.removeAll(ls2);
		return list;
	}

	public static List<String> readFileActual(String fileName) {
		File file = new File(fileName);
		List<String> nameList = new ArrayList<String>();
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			int line = 1;
			while ((tempString = reader.readLine()) != null) {
				tempString = tempString.substring(0, tempString.indexOf("_"));
				// System.out.println(tempString+"  行"+line);
				nameList.add(tempString.trim());
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return nameList;
	}
	public static List<String> readFileRemoveEndWith(String fileName) {
		File file = new File(fileName);
		List<String> nameList = new ArrayList<String>();
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			int line = 1;
			while ((tempString = reader.readLine()) != null) {
				tempString = tempString.substring(0, tempString.indexOf("."));
				  System.out.println(tempString);
				nameList.add(tempString.trim());
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return nameList;
	}
	
	public static List<String> readLogFileRemoveEndWith(String fileName) {
		File file = new File(fileName);
		List<String> nameList = new ArrayList<String>();
		BufferedReader reader = null;
		String exception ="";
		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = "";
			String theroyName = "";
			int line = 1;
			while ((tempString = reader.readLine()) != null) {
		    //  theroyName =tempString.substring(0, tempString.indexOf("/")+3);
		      theroyName = tempString.replaceAll("/", "_");
			   System.out.println(theroyName);
				nameInfos.put(theroyName, tempString);
				  System.out.println(theroyName);
				nameList.add(theroyName);
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return nameList;
	}
	
	public static List<String> readFileCatia(String fileName) {
		File file = new File(fileName);
		List<String> nameList = new ArrayList<String>();
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			int line = 1;
			while ((tempString = reader.readLine()) != null) {
				tempString = tempString.substring(0, tempString.indexOf("--"));
				// System.out.println(tempString+"  行"+line);
				nameList.add(tempString.trim());
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return nameList;
	}

	public static List<String> readFileAll_Info(String fileName) {
		File file = new File(fileName);
		List<String> nameList = new ArrayList<String>();
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			int line = 1;
			while ((tempString = reader.readLine()) != null) {
				// System.out.println(tempString+"  行"+line);
				nameList.add(tempString.trim());
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return nameList;
	}

	public static List<String> readFileTheroy(String fileName) {
		File file = new File(fileName);
		List<String> nameList = new ArrayList<String>();
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = "";
			String theroyName = "";
			int line = 1;
			while ((tempString = reader.readLine()) != null) {
				tempString = tempString.replaceAll("\\s+", " ");
				theroyName = tempString.substring(0, tempString.indexOf(" "));
				nameInfos.put(theroyName, tempString);
				// System.out.println(theroyName);
				nameList.add(theroyName);
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return nameList;
	}

	public static List<String> readFileLog(String fileName) {
		File file = new File(fileName);
		List<String> nameList = new ArrayList<String>();
		BufferedReader reader = null;
		String exception ="";
		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = "";
			String theroyName = "";
			int line = 1;
			while ((tempString = reader.readLine()) != null) {
				exception = tempString;
		      theroyName = tempString.substring(0, tempString.indexOf("/"));   //tempString.substring(0, tempString.indexOf("/")+3);
				//   System.out.println(theroyName);
				nameInfos.put(theroyName, tempString);
				//  System.out.println(theroyName);
				nameList.add(theroyName);
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return nameList;
	}

	public static List<String> NullDic(String fileName) {
		File file = new File(fileName);
		List<String> nameList = new ArrayList<String>();
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			int line = 1;
			while ((tempString = reader.readLine()) != null) {
				int endIndex = tempString.indexOf("/");
				tempString = tempString.substring(0, endIndex);
				// System.out.println(tempString+"  行"+line);
				nameList.add(tempString.trim());
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return nameList;
	}
}
